package com.bgt;

import java.lang.reflect.Method;
import java.lang.reflect.Type;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class ObjectTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	 private String pro;
	    @Override
	    public int doStartTag() throws JspException {
	        try {
	            JspWriter out = this.pageContext.getOut();
	         Object object=  this.pageContext.getAttribute(pro);
	         System.out.println(object.getClass().getName());
	            if(object == null) {
	                out.println("No object Found...");
	                return SKIP_BODY;
	            }
	            out.println("<table width='500px' border='1' align='center'>");
	            out.println("<tr>");
	            Class c=Class.forName(object.getClass().getName());
	            Method[] ms=c.getDeclaredMethods();
	            for (int i = 0; i < ms.length; i++) {
					Method m=ms[i];
				if(m.getName().indexOf("get")>=0){
					Object msg=(Object) m.invoke(object);
					out.println(msg);
				}
				}
	            out.println("</tr>");
	            out.println("</table>");
	        } catch(Exception e) {
	            throw new JspException(e.getMessage());
	        }
	        return SKIP_BODY;
	    }
	   
	    @Override
	    public int doEndTag() throws JspException {
	        return EVAL_PAGE;
	    }
	 
	    @Override
	    public void release() {
	        super.release();
	       System.out.println("jieshule...");
	    }

		public String getPro() {
			return pro;
		}

		public void setPro(String pro) {
			this.pro = pro;
		}
	   

}
